package hu.szyrt.bug.animations;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

public class ResizeAnimation extends Animation {

	private View view;
    private int originalWidth, originalHeight;
    private int newWidth, newHeight;
    private int diffWidth, diffHeight;

    public ResizeAnimation(View view, int newWidth, int newHeight){
        this.view = view;
        this.newWidth = newWidth;
        this.newHeight = newHeight;
        this.setFillAfter(true);
        this.setFillEnabled(true);
        this.setDuration(400);
        updateDimensions();
    }
    
    public void updateDimensions() {
    	this.originalWidth = view.getWidth();
        this.originalHeight = view.getHeight();        
        this.diffWidth = newWidth - originalWidth;
        this.diffHeight = newHeight - originalHeight;
	}
       
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t){
    	if(diffWidth != 0)
    		view.getLayoutParams().width = originalWidth + (int)(diffWidth * interpolatedTime);
    	if(diffHeight != 0)
    		view.getLayoutParams().height = originalHeight + (int)(diffHeight * interpolatedTime);
        view.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight){
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds(){
        return true;
    }
	
    
}
